//
// Description: 6039. K 次增加后的最大乘积
// Created by Loading on 2022/4/10.
//

#include <bits/stdc++.h>

using namespace std;

int maximumProduct(vector<int> &nums, int k) {
    /* 数据越均匀，乘积越大，每次将最小值增加即可 */
    constexpr int MOD = 1e9 + 7;
    // 由小到大优先级队列
    priority_queue<int, vector<int>, greater<>> q;
    for (auto x : nums) {
        q.emplace(x);
    }
    // 每次取最小值，增加后重新加入队列
    for (int i = 0; i < k; ++i) {
        int x = q.top();
        q.pop();
        ++x;
        q.emplace(x);
    }
    if (!q.top()) {
        return 0;
    }

    // 计算乘积
    long long res = 1;
    while (!q.empty()) {
        int x = q.top();
        q.pop();
        res = res * x % MOD;
    }

    return (int) res;
}

int main() {
    vector<int> nums{6, 3, 3, 2};
    int k = 2;
    auto res = maximumProduct(nums, k);
    cout << res << endl;

    return 0;
}